﻿namespace ConsoleApp5
{
    //5 Null传播器
    //空值传播器使用 ?. 运算符来表示

    internal class Program
    {
        public static void Main(string[] args)
        {
            Person person = null;
            string cityName = person?.Name; // 如果 person 为 null，cityName 也为 null
            Console.WriteLine("City Name: " + cityName);

            Address address = new Address();
            string city = address?.City; // address 不为 null，返回 City 值
            Console.WriteLine("City: " + city);
        }
    }

    class Person
    {
        public string Name { get; set; } = "尚";
    }

    class Address
    {
        public string City { get; set; } = "安徽";
    }
}